#include <cxxomfort/backports.hpp>
#include <cxxomfort/library/type_name.hpp>
#include <iostream>
#include <iomanip>


template <typename StringType, typename PrefixType>
void test_prefix_print(StringType const& str, PrefixType prefix) {
	using cxxomfort::string::starts_with;
	using cxxomfort::type_name;
	//std::cout<< "prefix test with str:"<< type_name<StringType>()<< " prefix:"<< type_name<PrefixType>()<< std::endl;
    std::cout << '\'' << str 
    << "' starts with '" << prefix << "': " 
    << starts_with(str,prefix) << '\n';
}

template <typename StringType, typename SuffixType>
void test_suffix_print(StringType const& str, SuffixType suffix) {
	using cxxomfort::string::ends_with;
	using cxxomfort::type_name;
	//std::cout<< "prefix test with str:"<< type_name<StringType>()<< " prefix:"<< type_name<SuffixType>()<< std::endl;
    std::cout << '\'' << str 
    << "' ends with '" << suffix << "': " 
    << ends_with(str,suffix) << '\n';
}
 
int main() {
	using namespace std;
	srand(time(0));
	
    std::cout<< std::ios_base::boolalpha;
    
    cout<< "-- Testing substr \n"<< endl;
    
    std::string abecedary = "The quick brown fox jumped over the lazy dog";
    
    const size_t ah = abecedary.size() / 2;
    for (unsigned i=0; i < abecedary.size(); i+=2) {
		size_t j= 1+ (rand() % ah);
		cout<< "substr at "<< setw(2)<< i<< " size "<< j<< " : ";
		cout<< "["<< cxxomfort::string::substr(abecedary, i, j)<< "]"<< endl;
	}
	cout<< endl;
    
    
    cout<< "-- Testing starts_with, ends_with \n"<< endl;

    using cxxomfort::fix::string_helpers::s;
    using cxxomfort::fix::string_helpers::sv;
    
    std::string helloWorld = "hello world";
    cout<< "std::string: "<< endl;
 
    test_prefix_print(helloWorld, sv("hello"));
    test_prefix_print(helloWorld, sv("goodbye"));
    test_prefix_print(helloWorld, 'h');
    test_prefix_print(helloWorld, 'x');
    cout<< endl;
    
    test_suffix_print(helloWorld, sv("world"));
    test_suffix_print(helloWorld, sv("goodbye"));
    test_suffix_print(helloWorld, 'd');
    test_suffix_print(helloWorld, 'x');
    cout<< endl;
    
    std::string_view byeWorld = "Bye world!";
    cout<< "std::string_view: "<< endl;

    test_prefix_print(byeWorld, sv("Bye"));
    test_prefix_print(byeWorld, sv("Hai"));
    test_prefix_print(byeWorld, 'B');
    test_prefix_print(byeWorld, 'C');
    cout<< endl;
    
    test_suffix_print(byeWorld, sv("!"));
    test_suffix_print(byeWorld, sv("?"));
    //size_t pos= helloWorld.find(string("hello"));
    //cout<< pos<< endl;
}

